home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / newsgrp / group03a.txt / 000073_icon-group-sender_Tue Apr 15 12:26:43 2003.msg < prev    next >
Internet Message Format  |  2003-12-22  |  2KB

  1. Return-Path: <icon-group-sender>
  2. Received: (from root@localhost)
  3.     by baskerville.CS.Arizona.EDU (8.11.1/8.11.1) id h3FJQgU11987
  4.     for icon-group-addresses; Tue, 15 Apr 2003 12:26:42 -0700 (MST)
  5. Message-Id: <200304151926.h3FJQgU11987@baskerville.CS.Arizona.EDU>
  6. From: Richard Bos <rlb@hoekstra-uitgeverij.nl>
  7. X-Newsgroups: comp.lang.icon
  8. Mail-Copies-To: nobody
  9. Subject: Re: Simplifying Integer Arithmetic
  10. User-Agent: MT-NewsWatcher/3.1 (PPC)
  11. Date: Tue, 15 Apr 2003 17:37:33 +0200
  12. X-Complaints-To: abuse@nl.uu.net
  13. To: icon-group@cs.arizona.edu
  14. Errors-To: icon-group-errors@cs.arizona.edu
  15. Status: RO
  16.  
  17. In article <JoVma.17461$Gb1.15725@nwrdny01.gnilink.net>,
  18.  "Frank J. Lhota" <NOSPAM.lhota.adarose@verizon.net> wrote:
  19.  
  20. > Within the file "src/h/config.h", we can guarantee that ROUNDS_TO_0 is
  21. > defined with the following preprocessor directives:
  22. > #ifndef ROUNDS_TO_0
  23. >    #if ( 5 / (-3) == -1 ) && ( (-5) / 3 == -1 ) && ( (-5) / (-3) == 1 )
  24. >       #define ROUNDS_TO_0 1
  25. >    #else
  26. >       #define ROUNDS_TO_0 0
  27. >    #endif
  28. > #endif                                  /* ROUNDS_TO_0 */
  29. > If there is some platform for which this does not set ROUNDS_TO_0 to the
  30. > appropriate value, you can set it in 'src/h/define.h'.
  31.  
  32. Well, let's see.
  33.  
  34. If the #if does not evaluate to true, then the implementation for that 
  35. very reason does not truncate to 0, so #define ROUNDS_TO_0 0 is correct.
  36.  
  37. If, OTOH, it does evaluate to true, then the requirement, in both the 
  38. C89 and the C99 Standard, that (a/b)*b + a%b == a, demands that the 
  39. modulo operator behaves as expected for platforms that truncate to 0, 
  40. and #define ROUNDS_TO_0 1 is correct.
  41.  
  42. So whether the implementation does truncate towards zero or not, this 
  43. snippet is correct.
  44.  
  45. BTW, strictly speaking this is truncation, not rounding, but that's a 
  46. matter of terminology. A newbie like me certainly shouldn't dictate what 
  47. the Icon dev team calls things <g>.
  48.  
  49. Richard
  50.